package demo.controller;

import demo.binder.OutputBinding;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;


@RestController
public class KafkaController {


    @Autowired
    private OutputBinding outputBinding;

    @RequestMapping("/send")
    public void sendMessage(@RequestParam("type") String type, @RequestParam("message") String message) {
        try {
            outputBinding.output1().send(MessageBuilder.withPayload(message).setHeader("myType", type).build());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    @RequestMapping("/send2")
    public void sendMessage2(@RequestParam("message") String message) {
        try {
            outputBinding.output2().send(MessageBuilder.withPayload(message).build());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
